1
|
|
|
// Directives |
2
|
|
|
|
3
|
|
|
import {noop, clickNode} from './utilities' |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
let Directives = function (Vue) { |
7
|
|
|
Object.defineProperties(this, { |
8
|
|
|
Vue: {get: () => Vue}, |
9
|
|
|
confirmDefinition: { |
10
|
|
|
get: this.defineConfirm |
11
|
|
|
}, |
12
|
|
|
alertDefinition: { |
13
|
|
|
get: this.defineAlert |
14
|
|
|
} |
15
|
|
|
}) |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
Directives.prototype.defineConfirm = function () { |
19
|
|
|
const _this = this |
20
|
|
|
const DirectiveDefinition = {} |
21
|
|
|
|
22
|
|
|
const clickHandler = function (event, el, binding) { |
23
|
|
|
event.preventDefault() |
24
|
|
|
event.stopImmediatePropagation() |
25
|
|
|
|
26
|
|
|
let confirmMessage = (function () { |
27
|
|
|
if (binding.value && binding.value.message) { |
28
|
|
|
return binding.value.message |
29
|
|
|
} |
30
|
|
|
return typeof binding.value === 'string' ? binding.value : null |
31
|
|
|
})() |
32
|
|
|
|
33
|
|
|
let thenCallback = (function () { |
34
|
|
|
if (binding.value && binding.value.ok) { |
35
|
|
|
return binding.value.ok |
36
|
|
|
} else { |
37
|
|
|
return () => { |
38
|
|
|
// Unbind to allow original event |
39
|
|
|
el.removeEventListener('click', el.VuejsDialog.clickHandler, true) |
40
|
|
|
// Trigger original event |
41
|
|
|
clickNode(el) |
42
|
|
|
// Re-bind listener |
43
|
|
|
el.addEventListener('click', el.VuejsDialog.clickHandler, true) |
44
|
|
|
} |
45
|
|
|
} |
46
|
|
|
})() |
47
|
|
|
|
48
|
|
|
let catchCallback = (function () { |
49
|
|
|
if (binding.value && binding.value.cancel) { |
50
|
|
|
return binding.value.cancel |
51
|
|
|
} |
52
|
|
|
return noop |
53
|
|
|
})() |
54
|
|
|
|
55
|
|
|
_this.Vue.dialog.confirm(confirmMessage).then(thenCallback).catch(catchCallback) |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
DirectiveDefinition.bind = (el, binding) => { |
59
|
|
|
if (el.VuejsDialog === undefined) { |
60
|
|
|
el.VuejsDialog = {} |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
el.VuejsDialog.clickHandler = function clickEventHandler(event) { |
64
|
|
|
clickHandler(event, el, binding) |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
el.addEventListener('click', el.VuejsDialog.clickHandler, true) |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
DirectiveDefinition.unbind = (el) => { |
71
|
|
|
el.removeEventListener('click', el.VuejsDialog.clickHandler, true) |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
return DirectiveDefinition |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
Directives.prototype.defineAlert = function () { |
78
|
|
|
// |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
export default Directives |
82
|
|
|
|